package hos.demo;

import android.app.Application;
import android.content.Context;
import android.net.Uri;

import com.blankj.utilcode.util.FileIOUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.UriUtils;
import com.blankj.utilcode.util.Utils;
import com.google.gson.Gson;

import java.io.File;

import hos.core.ActivityManager;
import hos.core.AppCompat;
import hos.core.UriFileConvert;
import hos.util.carash.CrashAndroid;


/**
 * <p>Title: App </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2022/4/3 10:17
 */
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Utils.init(this);
        AppCompat.init(this, new UriFileConvert() {
            @Override
            public Uri convertUri(Context context, String s) {
                return UriUtils.file2Uri(FileUtils.getFileByPath(s));
            }

            @Override
            public File uri2File(Uri uri) {
                return UriUtils.uri2File(uri);
            }
        });
        String logDir = PathUtils.getExternalAppFilesPath();
        if (logDir == null) {
            logDir = PathUtils.getExternalAppCachePath();
            if (logDir == null) {
                logDir = PathUtils.getExternalDcimPath();
                if (logDir == null) {
                    logDir = PathUtils.getInternalAppFilesPath();
                }
            }
        }
        logDir = logDir + File.separator + "log";
        CrashAndroid.init(this, logDir, new hos.java.util.CrashUtils.OnCrashListener() {
            @Override
            public void onCrash(String crashFile, String time, String info) {
                FileIOUtils.writeFileFromString(crashFile, info, true);
            }
        });
//        HiLogManager.init(new HiLogConfig() {
//            @Override
//            public JsonParser injectJsonParser() {
//                return new JsonParser() {
//                    @Override
//                    public String toJson(Object src) {
//                        return new Gson().toJson(src);
//                    }
//                };
//            }
//        }, new HiConsolePrinter());
    }
}
